/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
	"encoding/json"
	"fmt"
	"runtime"

	"github.com/spf13/cobra"
)

var (
	_Version_   = ""
	_GitCommit_ = ""
	_BuildDate_ = ""
)

type VersionInfo struct {
	Version   string `json:"Version"`
	GitCommit string `json:"GitCommit"`
	BuildDate string `json:"BuildDate"`
	GoVersion string `json:"GoVersion"`
}

// versionCmd represents the version command
var versionCmd = &cobra.Command{
	Use:   "version",
	Short: "version",
	Long:  `version info`,
	Run:   VersionRun,
}

func init() {
	rootCmd.AddCommand(versionCmd)

	// Here you will define your flags and configuration settings.

	// Cobra supports Persistent Flags which will work for this command
	// and all subcommands, e.g.:
	// versionCmd.PersistentFlags().String("foo", "", "A help for foo")

	// Cobra supports local flags which will only run when this command
	// is called directly, e.g.:
	// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
func VersionRun(cmd *cobra.Command, args []string) {
	versionInfo, err := json.Marshal(&VersionInfo{Version: _Version_, GitCommit: _GitCommit_, BuildDate: _BuildDate_, GoVersion: runtime.Version()})
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(versionInfo))
}
